﻿package frEngine.effectEditTool.manager
{
    import baseEngine.core.*;
    import baseEngine.modifiers.*;
    import baseEngine.system.*;
    import flash.utils.*;
    import frEngine.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.animateControler.transformControler.*;
    import frEngine.effectEditTool.shakeInstance.*;
    import frEngine.postProcess.*;

    public class Game3DControler extends Pivot3D
    {
        public var _isShakeing:Boolean = false;
        private var _shakeList:Dictionary;
        private var _shakeModify:Modifier;
        private var _endFrame:int;
        public var startShakeFrame:int = 0;
        private var _shakeType:int;
        private var _shakeStrength:Number;
        private var _useBlur:Boolean;
        private var _blurStrength:Number;
        private var _useDirection:Boolean;
        private var _frame:int = -1;
        private var _preValue1:Number = -1;
        public var shakeFun:Function;
        public static const defaultShake:DefaultShake = new DefaultShake();

        public function Game3DControler()
        {
            this._shakeList = new Dictionary(false);
            super("shake");
            this.timerContorler = TimeControler.createTimerInstance(null, null);
            this.shakeFun = this.shakeHander;
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            return;
        }// end function

        public function parserKeyFrames(param1:String, param2:Object) : Modifier
        {
            var _loc_3:* = this._shakeList[param1];
            if (_loc_3 == null)
            {
                this.x = 0;
                _loc_3 = new PosXControler();
                this._shakeList[param1] = _loc_3;
                _loc_3.targetObject3d = this;
            }
            _loc_3.parserKeyFrames(param2);
            return _loc_3;
        }// end function

        public function checkShake(param1:Object, param2:int) : void
        {
            if (this._isShakeing)
            {
                return;
            }
            this._shakeType = param1.type;
            this._shakeStrength = param1.shakeStrength;
            this._useBlur = param1.blur;
            this._blurStrength = param1.blurStrength;
            this._useDirection = param1.direction;
            var _loc_3:* = param1.shakeId;
            this._shakeModify = this._shakeList[_loc_3];
            if (!this._shakeModify)
            {
                this._shakeModify = this.parserKeyFrames(_loc_3, param1.keyFrames);
            }
            PostProcess.instance.enableBlueFilter(this._useBlur);
            this._animateControlerList[AnimateControlerType.PosX] = this._shakeModify;
            this._shakeModify.offsetFrame = this.timerContorler.curFrame - param2;
            this._endFrame = this.timerContorler.curFrame + (this._shakeModify.defaultLable.to - param2);
            this._isShakeing = true;
            return;
        }// end function

        public function stopShake() : void
        {
            this._shakeModify = null;
            this._isShakeing = false;
            return;
        }// end function

        override public function update(param1:int = 0) : void
        {
            var _loc_5:Number = NaN;
            if (!this._shakeModify)
            {
                return;
            }
            var _loc_2:* = this.timerContorler.curFrame;
            if (_loc_2 == this._frame)
            {
                return;
            }
            this._frame = _loc_2;
            var _loc_3:* = this.x;
            var _loc_4:* = this._frame > this._endFrame;
            if (_loc_4)
            {
                _loc_3 = 0;
            }
            if (_loc_4)
            {
                this.stopShake();
            }
            else
            {
                this._shakeModify.toUpdateAnimate(false);
            }
            if (_loc_3 == this._preValue1)
            {
                return;
            }
            this._preValue1 = _loc_3;
            if (this._useBlur)
            {
                _loc_5 = _loc_3 * this._blurStrength;
                if (_loc_5 < 0)
                {
                    _loc_5 = 0;
                }
                else if (_loc_5 > 1)
                {
                    _loc_5 = 1;
                }
                PostProcess.instance.JXmohu.changeStrength(_loc_5);
            }
            if (this._shakeType == 1)
            {
                _scene.sceneScale = 1 + _loc_3 * this._shakeStrength;
            }
            else if (this._shakeType == 2)
            {
                this.shakeFun.apply(null, [this._useDirection, _loc_3 * this._shakeStrength * 360]);
            }
            return;
        }// end function

        private function shakeHander(param1:Boolean, param2:Number) : void
        {
            Global3D.camera.setShakeValue(0, 0, param2 * this._shakeStrength * 360);
            return;
        }// end function

    }
}
